import requests
import time
import json



dlist = []



def getData():
    total = 0
    url = "http://bjhhaxcsjjh.n.gongyibao.cn/api/trade/trade/jet/selectSimpleByPage"
    timeNow = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    params = {
        'pageNo':1,
        'pageSize':100,
        'pageState':1,
        'startDate':'2020-01-22 00:00:00',
        'endDate' :timeNow
    }
    res = requests.get(url,params=params)
    res = json.loads(res.content.decode('utf-8'))
    count = res['dataPoints']['total']
    pageCount = res['dataPoints']['pages']
    print("总有"+str(count)+"条数据 共"+str(pageCount)+"页")
    for k in range(1,pageCount+1):
        print("正在处理第"+str(k)+"页...")
        params['pageNo']=k
        response = requests.get(url, params=params)
        while(response.status_code!=200):
            response = requests.get(url, params=params)
        response = json.loads(response.content.decode('utf-8'))
        list = response['dataPoints']['list']
        for item in list:
            ditem = {}
            ditem['jjh'] = "韩红爱心慈善基金会"
            ditem['jzdw'] = item['donationName']
            ditem['lx'] = '捐款'
            ditem['je'] = item['amount']
            total=total+item['amount']
            ditem['rq'] = item['createTime'][0:10]
            ditem['jydh'] = item['tradeNo']
            dlist.append(ditem)
    print(total)



if __name__ == '__main__':
    getData()
    print(dlist)
